﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Globalization;
using KPIS.GERP.GHRMS.BLL;
using Telerik.Web.UI;
using System.Data;

namespace KPIS.GERP.GHRMS.APP.App_UI.Forms
{
    public partial class HRDEvaluateDateConfig : System.Web.UI.Page
    {
        private HRDEvaluationBLL cmd = new HRDEvaluationBLL();
        private SsMng ssMng = new SsMng();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                //CultureInfo th = System.Globalization.CultureInfo.GetCultureInfo("th-TH");
                string strYear = Convert.ToDateTime(DateTime.Now.ToString()).ToString("yyyy", CultureInfo.GetCultureInfo("th-TH"));
                txtRadYear.Text = strYear;
                LoadGridRound(strYear);                               
            }
                        
        }

        protected void LoadGridRound(string strYear)
        {
            grdRadRound.DataSource = cmd.LoadRound(strYear);
            grdRadRound.DataBind();
        }
        

        protected void grdRadRound_ItemCommand(object sender, GridCommandEventArgs e)
        {
            if (e.CommandName == "btnDelete")
            {
                int intRoundSeq = Convert.ToInt32((e.Item as GridDataItem).GetDataKeyValue("evaluation_round_seq"));
                cmd.DeleteRound(intRoundSeq, Convert.ToInt32(ssMng.EmpSeq));
            }
        }

        protected void cmdAddNew_Click(object sender, EventArgs e)
        {
            int intYear = Convert.ToInt32(txtRadYear.Value);

            string strUrl = string.Format("HRDEvaluateDateConfig_POP.aspx?Mode={0}", "AddNew" + "&Year=" + intYear);
            RadAjaxManager.GetCurrent(Page).ResponseScripts.Add(String.Format("radopen('{0}', '{1}');", strUrl, "POP"));
        }

        protected void txtRadYear_TextChanged(object sender, EventArgs e)
        {
            LoadGridRound(txtRadYear.Value.ToString());
        }

        protected void RadManager1_AjaxReQuest(object sender, AjaxRequestEventArgs e)
        {
            if (hdfYear.Value != null && hdfYear.Value != "")
            {
                txtRadYear.Value = Convert.ToDouble(hdfYear.Value);
                LoadGridRound(hdfYear.Value);
            }
        }

    }
}